package tsvetanv.inventory.dao;

import java.util.List;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import tsvetanv.inventory.model.Article;
import tsvetanv.inventory.model.Product;
import tsvetanv.inventory.util.dao.CustomHibernateDaoSupport;

/**
 * The <code>ProductDaoImpl</code> class implements the actions with database
 * related with {@link Product} class.
 * 
 * @author Tsvetan Vasilev
 * 
 */

@Repository("productDao")
public class ProductDaoImpl extends CustomHibernateDaoSupport implements
		ProductDao {

	@SuppressWarnings("unchecked")
	public Product findByProductId(int productId) {
		List<Product> products = getHibernateTemplate().find(
				"from Product where id=?", productId);
		return (products == null || products.isEmpty()) ? null : products
				.get(0);
	}

	@SuppressWarnings("unchecked")
	public Product findByProductName(String productName) {
		List<Product> products = getHibernateTemplate().find(
				"from Product where name=?", productName);
		return (products == null || products.isEmpty()) ? null : products
				.get(0);
	}

	// public void save(Product product) {
	// getHibernateTemplate().save(product);
	//
	// }
	//
	// public void update(Product product) {
	// getHibernateTemplate().update(product);
	//
	// }
	//
	// public void delete(Product product) {
	// getHibernateTemplate().delete(product);
	//
	// }
}
